<%--
  Created by IntelliJ IDEA.
  User: Ganesh
  Date: Dec 19, 2006
  Time: 4:54:35 PM
--%>
<%@ page language="java" %>
<%
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("max-age", 0);
    response.setDateHeader("Expires", 0);
%>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.users.User,
                 com.scalar.chiptrack.commons.SessionKeys"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>


<html>

<HEAD>
	<TITLE>ScalarSoft - ChipTrac - Wafer Data Entry </TITLE>
    <META http-equiv='Content-Type' content='text/html; charset=windows-1252'>
    <LINK href='<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css' type='text/css' rel='stylesheet'>
	<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
    <script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
    <script language='javascript' >

	function resetValues()
    {
        document.waferDataEntryForm.reset();
        onLoad();
    }

    function save()
	{
        errors  = "";
        var pa  = document.getElementById("message");
        pa.innerHTML = '';
        success = false;

        var form		            = document.waferDataEntryForm;
		var openerForm	            = window.opener.document.forms[0];
        var openerFormWaferIdsCtrl  = eval( openerForm['lotCorrection.waferIds'] )
        var openerFormWaferQtyIn    = eval(openerForm['lotCorrection.waferQtyIn'].value );

        var waferIdCtrl             =  form.waferId;
        if ( waferIdCtrl.length != null )
        {
            var waferIds = "";
            var lengthOfSelectedWaferIds = 0;

            for ( i = 0; i < waferIdCtrl.length; i++ )
            {
                if( waferIdCtrl[i].checked == true )
                {
                    lengthOfSelectedWaferIds++;
                }
            }
            if( eval(lengthOfSelectedWaferIds) == 0 )
            {
                pa.innerHTML = "<li>Please select Wafers</li>";
                return;
            }
            if( eval(openerFormWaferQtyIn) < eval(lengthOfSelectedWaferIds) )
            {
                pa.innerHTML = "<li>Wafers selected should not be more than the Wafer Quantity In</li>";
                return;
            }
            if( eval(openerFormWaferQtyIn) > eval(lengthOfSelectedWaferIds) )
            {
                pa.innerHTML = "<li>Wafers selected should not be less than the Wafer Quantity In</li>";
                return;
            }
            //START: ASSIGNING WAFER IDS TO THE PARENT WINDOW
            waferIds = "";
            for ( i = 0; i < waferIdCtrl.length; i++ )
            {
                if( waferIdCtrl[i].checked == true )
                {
                    waferIds = waferIds + ( i + 1 ) + ";" ;
                }
            }
            //END
            openerFormWaferIdsCtrl.value = waferIds;
        }
        closeWindow();
    }
    function closeWindow()
    {
        window.close();
    }
    function onLoad()
    {
        var form		            = document.waferDataEntryForm;
		var openerForm	            = window.opener.document.forms[0];
        var openerFormWaferIdsCtrl  = eval( openerForm['lotCorrection.waferIds'] );
        var waferIdCtrl             = form.waferId;
        var enteredWaferIdsArr      = openerFormWaferIdsCtrl.value.split(";");
        //START: TO POPULATE ALREADY ENTERED VALUES
        if ( waferIdCtrl != null )
        {
            if ( waferIdCtrl.length )
            {
                var waferIdsCount           = waferIdCtrl.length;
                var enteredwaferIdsCount    = enteredWaferIdsArr.length;
                var minCount                = ( waferIdsCount > enteredwaferIdsCount ) ? enteredwaferIdsCount : waferIdsCount;

                for ( i = 0; i < 25; i++ )
                {
                    for ( j = 0; j < minCount; j++ )
                    {
                        if( eval( enteredWaferIdsArr[j] -1 ) == i )
                        {
                            waferIdCtrl[i].checked = true;
                        }
                    }
                }
            }
        }
        //END
    }

    /*To select all the checkboxs and deselect the all checkboxes*/
    function setSelectAllWaferIds(Object)
    {
        var selId = document.waferDataEntryForm.waferId;
        var count = 0;


        if (typeof Object.length =='undefined')
        {

           if( Object.checked == true )
           {
               document.waferDataEntryForm.waferId.checked = true;
               for ( count = 0; count < selId.length; count ++ )
               {
                    selId[count].checked = true;
               }
            }
            else
            {
               document.waferDataEntryForm.waferId.checked = false;
               for ( count = 0; count < selId.length; count ++ )
               {
                    selId[count].checked = false;
               }
            }
        }
    }

    /*if deselect the checkbox, to deselect the SelectAll checkbox*/
    function deSelectWaferIds()
    {
        var selId = document.waferDataEntryForm.waferId;
        var selAll = document.waferDataEntryForm.waferIds;

        for( var i=0; i< selId.length;i++ )
        {
            if(selId[i].checked+""=='false')
            {
                document.waferDataEntryForm.waferIds.checked = false;
                return;
            }
            if(selId[i].checked+""=='true')
            {
                document.waferDataEntryForm.waferIds.checked = true;
            }
        }
    }

    </script>
</HEAD>
<%
    User user = ( User ) session.getAttribute ( SessionKeys.USER_KEY );
    if ( user != null )
    {
%>
<BODY bgcolor='ffffff' marginheight='0' marginwidth='0' topmargin='0' leftmargin='0' onLoad='onLoad()'>

    <TABLE align='center' border='0' width='100%' >
        <TR>
            <td align='center' class="NArialW">Wafer Data Entry</td>
        </TR>
        <TR>
            <TD align='center'>&nbsp;</TD>
        </TR>
        <form name="waferDataEntryForm" action="">
        <%
            int waferQty = 0;
            try
            {
                waferQty = Integer.parseInt( request.getParameter( "waferQty" ) );
            }
            catch( Exception ex )
            {
                waferQty = 0;
            }

            if( waferQty == 0 )
            {
        %>
        <TR>
            <TD align='center'><font class="NArialL" color="red">Wafer Qty Should be Greater zero / Not Entry </font></TD>
        </TR>
        <TR>
            <TD align='center'><font class="NArialL">&nbsp;</font></TD>
        </TR>
        <TR>
            <TD align='center'><a href="javascript:close()" title='Click here to close the window'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" ></a></TD>
        </TR>
        <%
            }
            else
            {
        %>
         <TR>
           <TD class="NArialL">
           <input type="checkbox" name="waferIds" styleClass="txfield" onClick="javascript:setSelectAllWaferIds(this)"/>
           <font class="NArialL">Select All &nbsp;</font>

           </TD>
         </TR>

        <TR>
            <TD align='center'>
			    <TABLE align="center" border="0" width="100%">
				    <TR>
				        <TD width="100%" colspan='5' class="NArialL">&nbsp;<FONT id="message" size=1 color='FF0000'></FONT></TD>
				    </TR>
            <%
                    for( int count = 0; count < 25 ; count++ )
                    {
            %>
            <%          if( count % 5 == 0 ) { %> <TR> <% } %>
                        <TD  class="NArialL">
                            <input type="checkbox" name="waferId" styleClass="txfield" onClick="javascript:deSelectWaferIds()"/>&nbsp;Wafer-<%=count+1%>&nbsp;&nbsp;&nbsp;
                        </TD>
            <%
                    }
            %>
                </TABLE>
            </TD>
        </TR>
        <TR><TD align='center'>&nbsp;</TD></TR>
        <TR>
            <TD align='center'>
                    <a href="javascript:save()" title='Click here to Save Wafer Data Entry'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" ></a>&nbsp;&nbsp;&nbsp;
                    <a href="javascript:resetValues()" title='Click here to reset all field values'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" ></a>&nbsp;&nbsp;&nbsp;
                    <a href="javascript:window.close()" title='Click here to close the window'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" ></a>
            </TD>
        </TR>

    <%
      }
    %>
        </form>
    </table>
</body>
<%
    }
    else
    {
%>
    <BODY bgcolor='ffffff' marginheight='0' marginwidth='0' topmargin='0' leftmargin='0' >
    <TABLE cellpadding='0' cellspacing='0' bgcolor='FDF5E6' border="0" width="100%"  height="100%" align=center>
        <TR>
            <TD>
                <TABLE align="center" border="0" width="40%" bgcolor="#FDF5E6">
                    <TR><TD>&nbsp;</TD></TR>
                    <TR><TD align="center" ><font class="NArialL" ><font color="red"><b>Session has been time out , Please close this window and login again.</b></font></font></TD></TR>
                    <TR><TD>&nbsp;</TD></TR>
                    <TR><TD align="center" ><a href="javascript:window.close();"><font class='NArialL'>[Close this window]</font></a></TD></TR>
                </TABLE>
            </TD>
       </TR>
       <TR><TD>&nbsp;</TD></TR>
    </TABLE>
    </BODY>
<% } %>
</html>
